//
//  AuothToll.swift
//  WBSwift
//
//  Created by maker on 2016/11/14.
//  Copyright © 2016年 maker. All rights reserved.
//

import UIKit

class UserInfoViewModel {
    static let shareInstance :UserInfoViewModel = UserInfoViewModel()
    var user : UserInfo?
    var homePath : String{
        let accountPath = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true).first!
        return (accountPath as NSString).appendingPathComponent("userInfo.plist")
    }
    
    var isLogin :Bool {
        
        if user == nil {
            return false
        }
        let time = user?.expires_date
        return time?.compare(Date()) == ComparisonResult.orderedDescending
    }
    
    init() {
        user = NSKeyedUnarchiver.unarchiveObject(withFile: homePath) as? UserInfo
    }
}
